<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SwtMachine extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'swt_machine';
    protected $guarded = [];

    public function merchant()
    {
        return $this->belongsToMany(SwtMerchant::class,'swt_merchant_machine','machine_id','merchant_id')->withPivot(['percent','is_owner','deposit_now']);
    }

    public function merchant_owner()
    {
        return $this->belongsToMany(SwtMerchant::class,'swt_merchant_machine','machine_id','merchant_id') -> withPivot(['percent','is_owner','deposit_now']) -> wherePivot('is_owner',1);
    }

    public function goods()
    {
        return $this->belongsToMany(SwtGood::class,'swt_machine_goods','machine_id','goods_id');
    }
}
